

const Router = require('koa-router')
const { formatError } = require('../constant/error.type')

const { create, update, query, statusQuery, adminQuery, auditQueryAll, auditStatusQueryAll, audit, remove } = require('../controller/leave.controller')
const { auth, verifyAdmin } = require('../middleware/auth.middleware')
const { validatort } = require('../middleware/validator.middlewear')


const router = new Router({ prefix: '/leave' })

router.post('/', auth,
    validatort(
        { remark: { type: 'string', required: true }, dayNum: { type: 'number', required: true } },
        formatError),
    create)

router.put('/:id', auth, validatort(
    { remark: { type: 'string', required: true }, dayNum: { type: 'number', required: true } },
    formatError), update)

router.get('/', auth, query)

router.get('/:status', auth, statusQuery)

router.get('/admin/all', auth, verifyAdmin, adminQuery)

router.get('/admin/audit', auth, verifyAdmin, auditQueryAll)

router.get('/audit/:status', auth, verifyAdmin, auditStatusQueryAll)

router.put('/audit/:id/:status', auth, verifyAdmin, audit)

router.delete('/:id', auth, remove)

module.exports = router